<template>
	<div id="app">
		<router-view :finished="finished"></router-view>
	</div>
</template>

<script>
import { updateFinished, updateNow } from './createAccount'
export default {
	name: 'dlb-wallet',
	data() {
        return {
            finished: false
        }
    },
	mounted(){
		// 监控更新结果
        this.finishedFunc()
	},
	methods:{
		finishedFunc(){
            updateFinished((res)=>{
                console.log(res)
                if(res){
                    // 监听若有新版本->自动下载->下载成功唤起弹框是否立即安装升级
                    const h = this.$createElement;
                    var arr = 'zh-cn'
                    if(this.$i18n.locale == 'en'){
                        arr = res.releaseNodeEn
                    }else{
                        arr = res.releaseNode
                    }
                    const str = []
                    for(var i = 0; i < arr.length; i++){
                        str.push(h('p', null, arr[i]))
                    }
                    this.$msgbox({
                        title: res.version + this.$t('settings.versionInfo'),
                        // message: h('p', null, [
                        //     h('p', null, res),
                        //     h('p', null, res.releaseNode)
                        // ]),
                        message: h('p', null, str),
                        showCancelButton: true,
                        confirmButtonText: this.$t('settings.updater'),
                        cancelButtonText: this.$t('form.cancel'),
                        beforeClose: (action, instance, done) => {
                            if (action === 'confirm') {
								this.finished = false
                                instance.confirmButtonLoading = true;
                                instance.confirmButtonText = this.$t('settings.updating');
                                setTimeout(() => {
                                    done();
                                    setTimeout(() => {
                                        instance.confirmButtonLoading = false;
                                        updateNow()
                                    }, 300);
                                }, 3000);
                            } else {
								this.finished = true
                                done();
                            }
                        }
                    }).then(action => {
                        // this.$message({
                        //     type: 'info',
                        //     message: 'action: ' + action
                        // });
                    });
                }
            })
        }
	}
}
</script>

<style>
#app{
	height:100%;
}
</style>
